package com.blast.comicsisland.model.community;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by dell on 2015/6/24.
 */
public class Info {
    private String id;
    private String bigbookid;
    private String userlevel;
    private String ispraised;
    private List<Picurl> picurls;
    private String downloadnum;
    private String gradescore;
    private String extendinfo;
    private String communityid;
    private String createtime;
    private String title;
    private String coverurl;
    private String praisenum;
    private String istop;
    private String profileimageurl;
    private String content;
    private String sujectname;
    private String screenname;
    private String replycount;
    private String bookname;
    private String userid;
    private String isgood;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getBigbookid() {
        return bigbookid;
    }

    public void setBigbookid(String bigbookid) {
        this.bigbookid = bigbookid;
    }

    public String getUserlevel() {
        return userlevel;
    }

    public void setUserlevel(String userlevel) {
        this.userlevel = userlevel;
    }

    public String getIspraised() {
        return ispraised;
    }

    public void setIspraised(String ispraised) {
        this.ispraised = ispraised;
    }

    public List<Picurl> getPicurls() {
        return picurls;
    }

    public void setPicurls(List<Picurl> picurls) {
        this.picurls = picurls;
    }

    public String getDownloadnum() {
        return downloadnum;
    }

    public void setDownloadnum(String downloadnum) {
        this.downloadnum = downloadnum;
    }

    public String getGradescore() {
        return gradescore;
    }

    public void setGradescore(String gradescore) {
        this.gradescore = gradescore;
    }

    public String getExtendinfo() {
        return extendinfo;
    }

    public void setExtendinfo(String extendinfo) {
        this.extendinfo = extendinfo;
    }

    public String getCommunityid() {
        return communityid;
    }

    public void setCommunityid(String communityid) {
        this.communityid = communityid;
    }

    public String getCreatetime() {
        return createtime;
    }

    public void setCreatetime(String createtime) {
        this.createtime = createtime;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getCoverurl() {
        return coverurl;
    }

    public void setCoverurl(String coverurl) {
        this.coverurl = coverurl;
    }

    public String getPraisenum() {
        return praisenum;
    }

    public void setPraisenum(String praisenum) {
        this.praisenum = praisenum;
    }

    public String getIstop() {
        return istop;
    }

    public void setIstop(String istop) {
        this.istop = istop;
    }

    public String getProfileimageurl() {
        return profileimageurl;
    }

    public void setProfileimageurl(String profileimageurl) {
        this.profileimageurl = profileimageurl;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getSujectname() {
        return sujectname;
    }

    public void setSujectname(String sujectname) {
        this.sujectname = sujectname;
    }

    public String getScreenname() {
        return screenname;
    }

    public void setScreenname(String screenname) {
        this.screenname = screenname;
    }

    public String getReplycount() {
        return replycount;
    }

    public void setReplycount(String replycount) {
        this.replycount = replycount;
    }

    public String getBookname() {
        return bookname;
    }

    public void setBookname(String bookname) {
        this.bookname = bookname;
    }

    public String getUserid() {
        return userid;
    }

    public void setUserid(String userid) {
        this.userid = userid;
    }

    public String getIsgood() {
        return isgood;
    }

    public void setIsgood(String isgood) {
        this.isgood = isgood;
    }

    //----------------------------->
    //解析部分
    /**
     *"info": [
     {
     "id": 291565, "bigbookid": 0, "userlevel": "1", "ispraised": 0,
     "picurls": [
     {
     "height": 501,
     "width": 393,
     "smallpicture": "http://sqtp.1391.com/2015-05-03/792370/
     BodyPart_8e1bb267-3e3e-4ec6-9c95-8e3c7a7851e0_small.jpg",
     "bigpicture": "http://sqtp.1391.com/2015-05-03/792370/
     BodyPart_8e1bb267-3e3e-4ec6-9c95-8e3c7a7851e0.jpg" }
     ],
     "downloadnum": 26317,
     "gradescore": 0,
     "extendinfo": null,
     "communityid": 3,
     "createtime": "2015-05-03 14:29:47",
     "title": "纯情⼀一枚",
     "coverurl": null,
     "praisenum": 9217,
     "istop": 0,
     "profileimageurl": "http://q.qlogo.cn/qqapp/100573263/
     BE0448EAA97ED100DA20DAC3AB627DDF/100",
     "content": "纯情⼀一枚",
     "sujectname": null, "screenname": "⽉月童", "replycount": 879, "bookname": null,
     "userid": 792370, "isgood": 1
     },
     */

    public void jsonParse(JSONObject object) {
        try {
            id = object.getString("id");
            userlevel = object.getString("userlevel");
            downloadnum = object.getString("downloadnum");
            createtime = object.getString("createtime");
            communityid = object.getString("communityid");
            title = object.getString("title");
            praisenum = object.getString("praisenum");
            profileimageurl = object.getString("profileimageurl");
            content = object.getString("content");
            screenname = object.getString("screenname");
            replycount = object.getString("replycount");
            userid = object.getString("userid");
            isgood = object.getString("isgood");
            JSONArray jsonArray = object.getJSONArray("picurls");
            if (picurls == null) {
                picurls = new LinkedList<>();
            }
            for (int i = 0; i < jsonArray.length(); i++) {
                Picurl picurl = new Picurl();
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                picurl.jsonParse(jsonObject);
                picurls.add(picurl);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
